package com.xiaobaibai.controller;

import com.xiaobaibai.bo.ProductEs;
import com.xiaobaibai.response.ResponseFormat;
import com.xiaobaibai.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "搜索接口")
@RequestMapping("/search")
@CrossOrigin
public class SearchController {

    @Autowired
    private IProductService productService;

    @ApiOperation("搜索商品")
    @GetMapping("")
    public ResponseFormat searchProduct(@RequestParam(value = "productName")String productName){

        List<ProductEs> list = productService.searchProduct(productName);

        return ResponseFormat.ok("获取搜索结果成功",list);

    }

    @GetMapping("/associatedWords")
    @ApiOperation("联想搜索")
    public ResponseFormat associatedWords(@RequestParam(value = "search")String search){

        List<String> list = productService.associatedWords(search);

        return ResponseFormat.ok("联想词获取成功",list);
    }

}
